package com.bootdo.market.controller;

import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.market.domain.PlatformDataRepeatDO;
import com.bootdo.market.service.PlatformDataRepeatService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author jinse
 * @email market@jinse.com
 * @date 2019-03-31 12:16:29
 */

@Controller
@RequestMapping("/market/platformDataRepeat")
public class PlatformDataRepeatController {
    @Autowired
    private PlatformDataRepeatService platformDataRepeatService;

    @GetMapping()
    @RequiresPermissions("market:platformDataRepeat:platformDataRepeat")
    String PlatformDataRepeat(@RequestParam Map<String, Object> params, Model model) {
        model.addAttribute("sdkrepeatdau", params.get("sdkrepeatdau"));
        model.addAttribute("id", params.get("id"));
        return "market/platformDataRepeat/platformDataRepeat";
    }

    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("market:platformDataRepeat:platformDataRepeat")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<PlatformDataRepeatDO> platformDataRepeatList = platformDataRepeatService.list(query);
        int total = platformDataRepeatService.count(query);
        PageUtils pageUtils = new PageUtils(platformDataRepeatList, total);
        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("market:platformDataRepeat:add")
    String add() {
        return "market/platformDataRepeat/add";
    }

    @GetMapping("/edit/{id}")
    @RequiresPermissions("market:platformDataRepeat:edit")
    String edit(@PathVariable("id") Integer id, Model model) {
        PlatformDataRepeatDO platformDataRepeat = platformDataRepeatService.get(id);
        model.addAttribute("platformDataRepeat", platformDataRepeat);
        return "market/platformDataRepeat/edit";
    }

    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("market:platformDataRepeat:add")
    public R save(PlatformDataRepeatDO platformDataRepeat) {
        if (platformDataRepeatService.save(platformDataRepeat) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("market:platformDataRepeat:edit")
    public R update(PlatformDataRepeatDO platformDataRepeat) {
        platformDataRepeatService.update(platformDataRepeat);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("market:platformDataRepeat:remove")
    public R remove(Integer id) {
        if (platformDataRepeatService.remove(id) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("market:platformDataRepeat:batchRemove")
    public R remove(@RequestParam("ids[]") Integer[] ids) {
        platformDataRepeatService.batchRemove(ids);
        return R.ok();
    }

}
